// CAN.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "CAN.h"
using namespace std;

ofstream log;
Bus myBus;
Node myNode1;
Node myNode2;
Node myNode3;

void run()
{
	log << "Node1 run." << endl;
	myNode1.run();
	log << "Node2 run." << endl;
	myNode2.run();
	log << "Node3 run." << endl;
	myNode3.run();
	log << "Bus run." << endl;
	myBus.run();
}

int _tmain(int argc, _TCHAR* argv[])
{
	srand(unsigned int(time(NULL)));
	log.open("CAN.log",std::ios_base::out|std::ios_base::trunc);
	
	DataFrame myDataFrame1(0,0);
	myDataFrame1.print();
	myNode1.setOutboundFrame(&myDataFrame1);
	
	DataFrame myDataFrame2(1,1);
	myDataFrame2.print();
	myNode2.setOutboundFrame(&myDataFrame2);

	RemoteFrame myRemoteFrame1(1,8);
	myRemoteFrame1.print();
	myNode3.setOutboundFrame(&myRemoteFrame1);
	
	for(int i=1; i<=250; i++)
	{
		log << "Run " << i  << ":" << endl;
		run();
		log << endl;
	}
	log.close();
	return 0;
}

